public class Text {

    public String LCS (String str1, String str2) {
        int max = 0;
        String str = "";
        for(int i = 0;i < str1.length();i++) {
            for(int j = 0; j < str2.length();j++) {
                int count  = 0;
                StringBuilder s = new StringBuilder();
                int m = i,n = j;
                while(m < str1.length() && n < str2.length() &&str1.charAt(m) == str2.charAt(n)) {
                    s.append(str1.charAt(m));
                    count++;
                    m++;
                    n++;

                }
                if(count > max) {
                    max = count;
                    str = s.toString();
                }
            }
        }
        return str;
    }
}
